package com.gitee.wsl.ext.number


/** Returns the floating-point modulus of a/b that wraps equally in positive and negative. */
fun posmod(a: Int, b: Int): Int {
    val value = a.rem(b)
    if ((value < 0 && b > 0) || (value > 0 && b < 0)) {
        return value + b;
    }
    return value
}

/** Returns the floating-point modulus of a/b that wraps equally in positive and negative. */
fun posmod(a: Long, b: Long): Long {
    val value = a.rem(b)
    if ((value < 0 && b > 0) || (value > 0 && b < 0)) {
        return value + b;
    }
    return value
}


fun Double.posmod(b: Double): Double {
    val value = this.rem(b)
    if ((value < 0 && b > 0) || (value > 0 && b < 0)) {
        return value + b;
    }
    return value
}

fun Float.posmod(b: Float): Float {
    val value = this.rem(b)
    if ((value < 0 && b > 0) || (value > 0 && b < 0)) {
        return value + b;
    }
    return value
}
